/**
 * Created by bai on 2015/8/22.
 */
var  PhoneGapRemind = function(){
    var clearTimeOutMinute = null;
    var clearTimeOutSecond = null;
    var bellRing = function(fun){
        var bool = true;

        var options = {};
        options.successFunction = function (data) {
            $.each(data.data[0],function(k,v){
                if(v>0){
                    bool = false;
                }
            })
            if(bool){

                    clearTimeout(clearTimeOutMinute);
                    clearTimeOutSecond =setTimeout(function(){bellRing(fun)},100);
                console.log("不响");

            }else{
                clearTimeout(clearTimeOutSecond);
                clearTimeOutMinute =  setTimeout(function(){bellRing(fun)},60000);
                console.log("响");
                NotificationMessenger.notify("通知", "你有新的服务哦");
                navigator.notification.beep(1);//铃声

                 fun();
            }

        };
        OrderingSystem.getAllTaskCount(options);
    }
    /*
     * 判断从后台进入到前台，也就是打开应用
     * */
    var inApp = function(fun){
        document.addEventListener("resume", yourCallbackFunction, false);
         function yourCallbackFunction(){
             NotificationMessenger.clear();
             fun();
         }
    }
    /*
    * phoneGap振动
    * */
    var vibrateOfPhoneGap = function(){
        navigator.vibrate(30);
    }
    return{
        init:function(fun,funInapp){
            inApp(funInapp)
            bellRing(fun);
        },
        vibrateOfPhoneGap:function(){
            vibrateOfPhoneGap()
        }
    }
}();